﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZHello.Test.Algorithm
{
    [TestClass]
    public class Sudo_test
    {
        private int NextBlank(int[] input, int index)
        {
            while (index < input.Length)
            {
                if (input[index] == 0)
                    return index;
                index++;
            }
            return -1;
        }

        [TestMethod]
        [DataRow(new int[] { 1, 2, 3, 4, 5, 0 }, true)]
        [DataRow(new int[] { 1, 2, 3, 4, 1, 0 }, false)]
        [DataRow(new int[] { 1, 2, 3, 4, 1, 0 }, false)]
        [DataRow(new int[] { 112, 41, 222, 3, 42, 1, 41, 47 }, false)]
        public void Check_test(int[] input, bool r0)
        {
            bool r1 = Check(input);
            Assert.IsTrue(r0 == r1);
        }

        private bool Check(int[] input)
        {
            int k = 0;
            for (int i = 0; i < input.Length; i++)
            {
                if (input[i] == 0)
                    continue;
                int pk = k;
                k = k ^ input[i];
                if (pk == k)
                    return false;
                if ((i + 1) % 9 == 0) //换行
                    k = 0;
            }
            return true;
        }

        public void Run(int[] input, out int[] output)
        {
            output = new int[input.Length];
            for (int i = 0; i < input.Length; i++)
            {
                output[i] = input[i];
            }
            int next = NextBlank(output, 0);
            while (next > 0)
            {
                output[next] = 1;

                next = NextBlank(output, next);
            }
        }
    }
}
